#pragma once

namespace SimpleLogger
{
	class CLogWriter;

	class CSimpleLogger :
		public ISimpleLogger
	{
		friend DWORD __stdcall	LogSettingThreadProc(LPVOID lpPara);
		friend DWORD __stdcall	LogWriteThreadProc(LPVOID lpPara);
	public:

		//interface function
		virtual bool			StartLogging();
		virtual void			EndLogging();
		virtual void			ReleaseInstance();
		virtual void			WriteLog(const wchar_t *pszLogContents, LogLevel loglevel, bool bForce = false);
		virtual void			WriteLog(const char *pszLogContents, LogLevel loglevel, bool bForce = false);

		static CSimpleLogger*	CreateInstance();
		static DWORD			FormatLogContents(const wchar_t *pszLogContents, LogLevel loglevel, LPBYTE pBuffer, DWORD dwSize, LoggerSetting *pSetting = NULL);
		static DWORD			FormatLogContents(const char *pszLogContents, LogLevel loglevel, LPBYTE pBuffer, DWORD dwSize, LoggerSetting *pSetting = NULL);
		static void				GetFormatTime(wchar_t pFormatTime[25]);
		static void				GetFormatTime(char pFormatTime[25]);

// 		void					ChangeLogSetting(const LoggerSetting &logSetting);
		bool					GetLogSetting(DWORD dwWaitTime);//millisecond
	protected:
		CSimpleLogger(void);
		virtual ~CSimpleLogger(void);

		static CRITICAL_SECTION	s_sectionWriteLog;
	private:
		static CSimpleLogger*	m_pLogger;
		bool					m_bLogging;
		HANDLE					m_hLogSettingThread;
		HANDLE					m_hLogWriteThread;

		LoggerSetting			m_logSetting;

		bool					m_bForceOutput;
		bool					m_bFormatContent;

		CLogWriter*				m_pWriter;
	};
}

